/**
 * 
 */
package com.igatewebsol.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import com.igatewebsol.actionforms.HotelAccomdationCategoryBean;
import com.igatewebsol.actionforms.HotelAccomdationTypeBean;
import com.igatewebsol.actionforms.HotelCurrencyTypeBean;
import com.igatewebsol.actionforms.HotelGroupBean;
import com.igatewebsol.actionforms.HotelMainBean;
import com.igatewebsol.dao.HotelDAO;

/**
 * @author R
 * 
 */
public class HotelDAOImpl extends BaseDAOImpl implements HotelDAO {

	public int createhotelgroup(HotelGroupBean hGroupBean) {
		Connection con = null;
		PreparedStatement ps = null;
		String inserthotelGroup = "insert into hotel_group_tab values(?,?,?,?)";
		int insertcount = 0;
		try {
			con = getDBConnection();
			con.setAutoCommit(false);
			ps = con.prepareStatement(inserthotelGroup,Statement.RETURN_GENERATED_KEYS);
			ps.setInt(1, 0);
			ps.setString(2, hGroupBean.getHotelgroupname());
			ps.setString(3, hGroupBean.getHotelgroupdesc());
			ps.setString(4, hGroupBean.getHotelgroupcreatedById());
			insertcount = ps.executeUpdate();
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return insertcount;
	}

	public ArrayList<HotelGroupBean> getHotelGroupByUserId(String userid) {
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs=null;
		ArrayList<HotelGroupBean> hgroupList=new ArrayList<HotelGroupBean>();
		String hotelgrpListQuery = "SELECT * FROM hotel_group_tab where hotel_group_createdByID=? ";
		try {
			con = getDBConnection();
			ps = con.prepareStatement(hotelgrpListQuery);
			ps.setString(1, userid);
			rs=ps.executeQuery();
			while(rs.next()){
				HotelGroupBean hGroupBean=new HotelGroupBean();
				hGroupBean.setHotelgroupid(rs.getString("hotel_group_id"));
				hGroupBean.setHotelgroupname(rs.getString("hotel_group_name"));
				hgroupList.add(hGroupBean);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return hgroupList;
	}

	public int createHotelCurrencyType(HotelCurrencyTypeBean hotelCurrencyTypeBean)  {
		
		Connection con = null;
		PreparedStatement ps = null;
		String inserthotelGroup = "insert into hotel_currency_type values(?,?,?)";
		int insertcount = 0;
		try {
			con = getDBConnection();
			con.setAutoCommit(false);
			ps = con.prepareStatement(inserthotelGroup,Statement.RETURN_GENERATED_KEYS);
			ps.setInt(1, 0);
			ps.setString(2, hotelCurrencyTypeBean.getHotelcurrencyname());
			ps.setString(3, hotelCurrencyTypeBean.getHotelcurrencydesc());
			insertcount = ps.executeUpdate();
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return insertcount;
	}

	public ArrayList<HotelCurrencyTypeBean> getHotelCurrencyTypeList() {
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs=null;
		ArrayList<HotelCurrencyTypeBean> hcurList=new ArrayList<HotelCurrencyTypeBean>();
		String hotelcurrListQuery = "SELECT * FROM hotel_currency_type";
		try {
			con = getDBConnection();
			ps = con.prepareStatement(hotelcurrListQuery);
			rs=ps.executeQuery();
			while(rs.next()){
				HotelCurrencyTypeBean hTypeBean=new HotelCurrencyTypeBean();
				hTypeBean.setHotelcurrencyid(rs.getInt("hotel_currency_id"));
				hTypeBean.setHotelcurrencyname(rs.getString("hotel_currency_name"));
				hcurList.add(hTypeBean);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return hcurList;
	}

	
	public ArrayList<HotelAccomdationTypeBean> gethotelAccodTypeList() {
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs=null;
		ArrayList<HotelAccomdationTypeBean> hcurList=new ArrayList<HotelAccomdationTypeBean>();
		String hotelQuery = "SELECT * FROM hotel_accomdation_type";
		try {
			con = getDBConnection();
			ps = con.prepareStatement(hotelQuery);
			rs=ps.executeQuery();
			while(rs.next()){
				HotelAccomdationTypeBean hTypeBean=new HotelAccomdationTypeBean();
				hTypeBean.setHotelaccomtypeid(rs.getInt("hotel_accom_type_id"));
				hTypeBean.setHotelaccomtypename(rs.getString("hotel_accom_typename"));
				hcurList.add(hTypeBean);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return hcurList;
	}

	public ArrayList<HotelAccomdationCategoryBean> getHotelAccodCategoryList() {
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs=null;
		ArrayList<HotelAccomdationCategoryBean> hcurList=new ArrayList<HotelAccomdationCategoryBean>();
		String hotelQuery = "SELECT * FROM hotel_accomdation_category";
		try {
			con = getDBConnection();
			ps = con.prepareStatement(hotelQuery);
			rs=ps.executeQuery();
			while(rs.next()){
				HotelAccomdationCategoryBean hTypeBean=new HotelAccomdationCategoryBean();
				hTypeBean.setHotelaccomcatid(rs.getInt("hotel_accom_cat_id"));
				hTypeBean.setHotelaccomcategoryname(rs.getString("hotel_accom_cat_name"));
				hcurList.add(hTypeBean);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return hcurList;
	}

	public int addhotelregisterdetails(HotelMainBean hmainForm) {
		System.out.println("Iam in addhotelregisterdetails in DAO Class");
		Connection con = null;
		PreparedStatement ps = null;
		String inserthotelreg = "insert into hotel_currency_type values(?,?,?)";
		int insertcount = 0;
		try {
			
			System.out.println(hmainForm.gethCurrencyTypeBean().getHotelcurrencyid());
			                 
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (ps != null) {
					ps.close();
				}
				if (con != null) {
					con.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return insertcount;
	}


}
